package com.ruoyi.project.modules.processBranchEnd.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.modules.processBranchEnd.domain.ProcessBranchEnd;
import com.ruoyi.project.modules.processBranchEnd.service.IProcessBranchEndService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分支结束Controller
 *
 * @author smallrain
 * @date 2022-04-03
 */
@Controller
@RequestMapping("/processBranchEnd/processBranchEnd")
public class ProcessBranchEndController extends BaseController {
    private String prefix = "processBranchEnd/processBranchEnd";

    @Autowired
    private IProcessBranchEndService processBranchEndService;

    @RequiresPermissions("processBranchEnd:processBranchEnd:view")
    @GetMapping()
    public String processBranchEnd() {
        return prefix + "/processBranchEnd";
    }

    /**
     * 查询分支结束列表
     */
    @RequiresPermissions("processBranchEnd:processBranchEnd:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProcessBranchEnd processBranchEnd) {
        startPage();
        List<ProcessBranchEnd> list = processBranchEndService.selectProcessBranchEndList(processBranchEnd);
        return getDataTable(list);
    }

    /**
     * 导出分支结束列表
     */
    @RequiresPermissions("processBranchEnd:processBranchEnd:export")
    @Log(title = "分支结束", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProcessBranchEnd processBranchEnd) {
        List<ProcessBranchEnd> list = processBranchEndService.selectProcessBranchEndList(processBranchEnd);
        ExcelUtil<ProcessBranchEnd> util = new ExcelUtil<ProcessBranchEnd>(ProcessBranchEnd.class);
        return util.exportExcel(list, "分支结束数据");
    }

    /**
     * 新增分支结束
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存分支结束
     */
    @RequiresPermissions("processBranchEnd:processBranchEnd:add")
    @Log(title = "分支结束", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProcessBranchEnd processBranchEnd) {
        return toAjax(processBranchEndService.insertProcessBranchEnd(processBranchEnd));
    }

    /**
     * 修改分支结束
     */
    @GetMapping("/edit/{branchEndId}")
    public String edit(@PathVariable("branchEndId") Long branchEndId, ModelMap mmap) {
        ProcessBranchEnd processBranchEnd = processBranchEndService.selectProcessBranchEndByBranchEndId(branchEndId);
        mmap.put("processBranchEnd", processBranchEnd);
        return prefix + "/edit";
    }

    /**
     * 修改保存分支结束
     */
    //@RequiresPermissions("processBranchEnd:processBranchEnd:edit")
    @Log(title = "分支结束", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProcessBranchEnd processBranchEnd) {
        return toAjax(processBranchEndService.updateProcessBranchEnd(processBranchEnd));
    }


    /**
     * 获取异常结束节点错误码信息
     *
     * @param branchEndId
     * @return java.lang.String
     * @author chenxiaoyu
     * @date 2022/4/6 下午11:53
     */
    @GetMapping("/get")
    @ResponseBody
    public AjaxResult get(Long branchEndId) {
        ProcessBranchEnd processBranchEnd = processBranchEndService.selectProcessBranchEnd2(branchEndId);
        return AjaxResult.success(processBranchEnd);
    }

    /**
     * 删除分支结束
     */
    @RequiresPermissions("processBranchEnd:processBranchEnd:remove")
    @Log(title = "分支结束", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(processBranchEndService.deleteProcessBranchEndByBranchEndIds(ids));
    }

    /**
     * 选择错误码
     */
    @GetMapping("/select/{entityId}")
    public String select(@PathVariable("entityId") Long entityId, ModelMap mmap) {
        mmap.put("entityId", entityId);
        return  "interface/interfaceArrange/selectErrorCode";
    }
}
